package cn.com.support.utils;

import java.util.Locale;

import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.stereotype.Component;

/**
 * 
 * 
 * @author Microbun 2012-2-13上午4:03:39
 * @version $Id: MessageSourceUtil.java 82 2012-03-06 14:17:26Z Microbun $
 * @since 1.0
 */
@Component
public class MessageSourceUtil implements MessageSourceAware {

	private static MessageSource messageSource;

	@Override
	public void setMessageSource(MessageSource messageSource) {
		MessageSourceUtil.messageSource = messageSource;
	}

	public static String getMessage(String code, Object[] args,
			String defaultMessage, Locale locale) {
		return messageSource.getMessage(code, args, defaultMessage, locale);
	}

	public static String getMessage(String code, Object[] args, Locale locale)
			throws NoSuchMessageException {
		return messageSource.getMessage(code, args, locale);
	}

	public static String getMessage(MessageSourceResolvable resolvable,
			Locale locale) throws NoSuchMessageException {
		return messageSource.getMessage(resolvable, locale);
	}

}
